package com.zoke.support.base;

import android.app.Service;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;

import com.zoke.support.http.CallBackStores;
import com.zoke.support.http.ZokeCallback;
import com.zoke.support.http.ZokeParams;
import com.zoke.support.utils.MessageHandlerList;

/**
 * 服务Base
 * 
 * @author JackWu
 * @version
 * @date 2014-11-13
 * @_QQ_ 651319154
 */
public class BaseService extends Service implements ZokeCallback {

	@Override
	public IBinder onBind(Intent arg0) {
		return null;
	}

	private Handler mHandler;
	/** 请求类对应的hashCode **/
	protected int mHashCode;

	@Override
	public void onCreate() {
		// 设置MessageHandlerList
		mHandler = new Handler() {
			@Override
			public void handleMessage(Message msg) {
				handleMsg(msg);
			}
		};
		String className = this.getClass().getName();
		MessageHandlerList.addHandler(className, mHandler);
		mHashCode = this.hashCode();
		/** 添加回调 **/
		CallBackStores.getCallback().addCallback(mHashCode, this);
		super.onCreate();
	}

	@Override
	public void onDestroy() {
		// 移除消息池中对应的handler
		String className = this.getClass().getName();
		MessageHandlerList.removeHandler(className);
		/** 移除callBack **/
		CallBackStores.getCallback().deleteCallback(this.hashCode(), this);
		super.onDestroy();
	}

	/**
	 * 接收handle的消息
	 * 
	 * @param msg
	 */
	protected void handleMsg(Message msg) {
	}

	@Override
	public void onSuccess(ZokeParams out) {

	}

	@Override
	public void onFails(ZokeParams out) {

	}

}
